package com.tyqx.hashchainbiz.controller.useProduct;

import com.tyqx.hashchainbean.module.UseProduct;
import com.tyqx.hashchainbean.vo.*;
import com.tyqx.hashchainbiz.service.UseProductService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(description = "领用物资")
@RestController
@RequestMapping("/useProduct")
@CrossOrigin
public class UseProductController {


    @Resource
    private UseProductService useProductService;

    @RequestMapping(value="/saveUseProduct", method = RequestMethod.POST)
    @ResponseBody
    public String saveUseProduct(@RequestBody UseProductVO useProductVO) throws Exception {

        String msg="";
        UseProduct useProduct=new UseProduct();
        useProduct.setAttachment(useProductVO.getAttachment());
        useProduct.setDonateId(useProductVO.getDonateId());
        useProduct.setUseName(useProductVO.getUseName());
        useProduct.setUsePerson(useProductVO.getUsePerson());
        useProduct.setUseTime(useProductVO.getUseTime());
        useProduct.setUseUnit(useProductVO.getUseUnit());
        useProduct.setUserName(useProductVO.getUserName());

        if(useProductService.useProduct(useProduct)>0){
            msg="添加领用物资成功";
        }else{
            msg="添加领用物资失败";
        }
        return msg;
    }

    @RequestMapping(value="/getUseProductById", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<UseProduct> getUseProductById(@RequestBody QueryParamVo queryParamVo) throws Exception {

        return useProductService.getUseProductById(queryParamVo.getDonateId(),queryParamVo.getUserName());
    }

    @RequestMapping(value="/getUseProductByTime", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<UseProduct> getUseProductByTime(@RequestBody QueryTimeParamVo queryTimeParamVo) throws Exception {

        return useProductService.getUseProductByTime(queryTimeParamVo.getStartTime(),
                queryTimeParamVo.getEndTime(),queryTimeParamVo.getUserName());
    }
}
